Pages
  • life with BSD
  • 2026-05-28 Using the units command to convert celsius to fahrenheit on FreeBSD
  • 2026-05-11 Trying out spinel on FreeBSD and fixed the blog feeds
  • 2026-04-27 Getting more information on a FreeBSD pkg without installing it
  • 2026-04-19 Feeling sherlocked - XDG's new Projects folder
  • 2026-04-07 The Laptop Integration Testing project
  • 2026-01-02 Migrating from bastille auto-starting jails from deprecated bastille_list
  • 2025-12-23 Understanding more about the pkg-status service for FreeBSD
  • 2025-12-07 Trying out flow control binaries for FreeBSD
  • 2025-11-07 Swift nightly preview for FreeBSD
  • 2025-11-02 Using jujutsu in a git compatible way to track freebsd ports
  • 2025-10-28 The sherlocking of the gemini protocol
  • 2025-10-09 How to change the options in a freebsd port
  • 2025-09-16 Waiting on Swift mainline for FreeBSD
  • 2025-08-25 Dmesg for Cable Matters USB 3.1 to 4 port Gigabit Ethernet Adapter
  • 2025-08-15 Generate a QR code with typst
  • 2025-07-31 Fixing jujutsu and leaky ascii escape sequences on FreeBSD
  • 2025-07-31 Swift now available as a package for FreeBSD
  • 2025-07-28 The FreeBSD project clarifies its stance on gen-ai powered contributions
  • 2025-07-28 The rustup question
  • 2025-07-08 Goodbye old friend, a tale
  • 2025-06-30 Configuring FreeBSD to network with a postmarketos phone over usb
  • 2025-06-25 swift (re)lands in the FreeBSD ports tree
  • 2025-06-24 typst a rust powered typesetting tool aiming at latex
  • 2025-06-19 Open Source Two Worlds thoughts
  • 2025-06-14 Taking a look at repolocli
  • 2025-06-09 Zig master builds now with FreeBSD support
  • 2025-06-07 Finding rust dependencies in Makefile.crates
  • 2025-06-05 Ripgrep or ripgrep-all
  • 2025-06-02 Ripgrep a nice Rust utility for ports spelunking
  • 2025-05-31 Get started with gpui on FreeBSD
  • 2025-05-29 Query freshports with Deno
  • 2025-05-27 Trying out Defuddle an npm tool via Deno
  • 2025-05-25 Deno for FreeBSD
  • 2025-05-23 A new beginning
life with BSD
  • life with BSD
  • 2026-05-28 Using the units command to convert celsius to fahrenheit on FreeBSD
  • 2026-05-11 Trying out spinel on FreeBSD and fixed the blog feeds
  • 2026-04-27 Getting more information on a FreeBSD pkg without installing it
  • 2026-04-19 Feeling sherlocked - XDG's new Projects folder
  • 2026-04-07 The Laptop Integration Testing project
  • 2026-01-02 Migrating from bastille auto-starting jails from deprecated bastille_list
  • 2025-12-23 Understanding more about the pkg-status service for FreeBSD
  • 2025-12-07 Trying out flow control binaries for FreeBSD
  • 2025-11-07 Swift nightly preview for FreeBSD
  • 2025-11-02 Using jujutsu in a git compatible way to track freebsd ports
  • 2025-10-28 The sherlocking of the gemini protocol
  • 2025-10-09 How to change the options in a freebsd port
  • 2025-09-16 Waiting on Swift mainline for FreeBSD
  • 2025-08-25 Dmesg for Cable Matters USB 3.1 to 4 port Gigabit Ethernet Adapter
  • 2025-08-15 Generate a QR code with typst
  • 2025-07-31 Fixing jujutsu and leaky ascii escape sequences on FreeBSD
  • 2025-07-31 Swift now available as a package for FreeBSD
  • 2025-07-28 The FreeBSD project clarifies its stance on gen-ai powered contributions
  • 2025-07-28 The rustup question
  • 2025-07-08 Goodbye old friend, a tale
  • 2025-06-30 Configuring FreeBSD to network with a postmarketos phone over usb
  • 2025-06-25 swift (re)lands in the FreeBSD ports tree
  • 2025-06-24 typst a rust powered typesetting tool aiming at latex
  • 2025-06-19 Open Source Two Worlds thoughts
  • 2025-06-14 Taking a look at repolocli
  • 2025-06-09 Zig master builds now with FreeBSD support
  • 2025-06-07 Finding rust dependencies in Makefile.crates
  • 2025-06-05 Ripgrep or ripgrep-all
  • 2025-06-02 Ripgrep a nice Rust utility for ports spelunking
  • 2025-05-31 Get started with gpui on FreeBSD
  • 2025-05-29 Query freshports with Deno
  • 2025-05-27 Trying out Defuddle an npm tool via Deno
  • 2025-05-25 Deno for FreeBSD
  • 2025-05-23 A new beginning

2026-05-28 Using the units command to convert celsius to fahrenheit on FreeBSD

At some point I had a sensor collecting temperature measurements and the format came out something like this.

Temperature: 29.86 °C

Nothing fancy however being non-fluent in Celsius-Fahrenheit conversions quite often when it came to conversions I tended to do the following:

  • Use search engine with search terms `convert celsius to fahrenheit`

  • Find a suitable candidate in the list of results and hope it isn't ad-laden drivel

  • Fire up a web browser if I had forgotten to start one or open a new tab

  • Go back to the terminal I was working in and copy the temperature

  • Paste it back into the browser tab after cursing I lost mouse focus

  • Finally get the results and pray that the webpage didn't have javascript preventing something as trivial as copying the calculation result

I had forgotten after some time that there are probably CLI tools for this but that got into another type of yak shave. But then I remembered reading (and forgetting) that FreeBSD includes in the base system something called units. It's built exactly for this purpose. A small excerpt from the manpage shows its history.

HISTORY

The units first appeared in NetBSD and was ported to FreeBSD 2.2.0.

Alright, let's try this out! Let's be cavalier and fire up the utility and use it...

$  units
751 units, 62 prefixes
You have: ?
unknown unit '?'
You have: help
unknown unit 'help'

Okay, I realized I have never used this tool at all so I have asked uninformed dumb things and got (dumb) answers. To be slightly fair to myself it's not listed in Wikipedia's list of POSIX commands.

Alright, let's try reading the docs since unlike in penguin-land manpages for base system commands are part of the batteries included.

$ man units
...
...
...

And we find out that the following:

FILES

/usr/share/misc/definitions.units The standard units file.

Excellent, well let's ask the handy file utility to do a base identification of what's inside.


$ file /usr/share/misc/definitions.units
/usr/share/misc/definitions.units: ASCII text

Nice, it's an ascii file. Alright, let's take a peak.


$ head /usr/share/misc/definitions.units

# primitive units

m                       !a!
kg                      !b!
sec                     !c!
coul                    !d!
candela                 !e!
usdollar                !f!
euro                    !g!

Okay, simple structured tabular-ish data. Let's grep around.


$ grep degrees /usr/share/misc/definitions.units
degreesrankine          5|9 K
degrankine              degreesrankine
degreerankine           degreesrankine

degreesrankine sounds like another trip to Wikipedia (not in this post) and other such search engine journeys.

Let's widen the grep a little. Sometimes being more vague gets you more


$ grep deg /usr/share/misc/definitions.units
degree                  1|180 pi-radian
grade                   .9 degree
arcdeg                  1 degree
arcmin                  1|60 arcdeg
k                       1.38047e-16 erg/degC
degC                    1&+273.15 K
degF                    5|9&255.37222222222222222222 K
degreesrankine          5|9 K
degrankine              degreesrankine
degreerankine           degreesrankine
degreaumur              10|8&+273.15 K
gasmark                 25|1&250 degF
Stufe                   25|1&125 degC

Okay, I think we have something here...

Let's try this again

$ units
You have: degC
You want: degF
         (-> x*1.8g 32g)
         (<- y*0.55555556g -17.777778g)

Whoops, need a number. Let's try again...

$ units
You have: 28.91
You want: degF
conformability error
        28.91
        0.55555556&255.37222 K

The program expects the temperature and the unit together on one line. And below is the working example:


$ units
You have: 28.91 degC
You want: degF
        84.038
        

I illustrated a lot of the typos and mistakes I did on my journey to calculate Celsius to Fahrenheit in order to hopefully illustrate things a little more. This process took me perhaps a few seconds or so.

Sometimes it's good to spell out in detail what is happening in that amount of time for others who are less cli fluent. It's a little late to learn UNIX when big iron UNIX computed the planet, unfortunately.

Note, a far more typical flow is to:

  • Find the name of base utility in FreeBSD

  • Read the manpage

  • Find the examples in the manpage

  • Adapt to your situation

Sometimes the answers to your problems are already there, you just need the instructions to unlock it.

PREVRANDOMNEXT